<template>
	<view class="qrcode" @tap="share()">
		<!-- #ifdef MP-WEIXIN -->
			<button type="primary" open-type="share" class="share-btn" ></button>
		<!-- #endif -->
		
		
		<image :src="codeUrl" mode="" class="code"></image>
	</view>
</template>

<script>
	import { appName } from '../../common/config.js';
	
	export default {
		data() {
			return {
				codeUrl: '/static/recommend_qrcode.png',
				appName: '',
				userinfo: {}
			};
		},
		onLoad() {
			var userinfo = uni.getStorageSync('userinfo');
			this.userinfo = userinfo;
			this.appName = appName;
			// this.codeUrl = 'http://qr.liantu.com/api.php?text=http://www.zhshop.net/mobile/user/register/rmobile/'+userinfo.mobile+'/merid/'+userinfo.merid
		},
		onShareAppMessage() {
			Request.send({
				url: 'share/addRecord',
				data: {
					type: 2
				},
				checkCode: false
			})
			return {
				title: this.appName,
				path: '/pages/coupon/index?rUserId='+this.userinfo.id,
			}
		},
		methods: {
			share: function(){
// 				uni.showModal({
// 					title:'提示',
// 					content: '请截图后发送给好友'
// 				})
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 2,
					imageUrl: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png",
					success: function (res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function (err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			}
		}
	}
</script>

<style>
		page{
			background: url(../../static/qrcode_bg.png);
			background-size: 100% 100%;
		}

		.qrcode{
			background: #4253EB;
			position: relative;
		}
		
		.qrcode .bg{
			width: 750upx;
		}

		.code{
			position: fixed;
			top:28.5%;
			margin: 0 auto;
			left: 0;
			right: 0;
			width: 400upx;
			height: 400upx;
		}
		
		.share-btn{
			position: fixed;
			width: 100%;
			height: 100%;
			background: red;
			z-index: 999;
			opacity: 0;
		}
</style>
